﻿using System;
namespace Q1
{
	public class question4
	{
		public question4()
		{
            Rectangle rectangle = new Rectangle(5, 10);
            Console.WriteLine("Rectangle Area: {0}", rectangle.Area);
            Console.WriteLine("Rectangle Valid: {0}", rectangle.IsValid());

            Square square = new Square(5);
            Console.WriteLine("Square Area: {0}", square.Area);
            Console.WriteLine("Square Valid: {0}", square.IsValid());

            Triangle triangle = new Triangle(3, 4, 5);
            Console.WriteLine("Triangle Area: {0}", triangle.Area);
            Console.WriteLine("Triangle Valid: {0}", triangle.IsValid());

        }

    }
    abstract class Shape
    {
        public abstract double Area { get; }
        public abstract bool IsValid();
    }

    class Rectangle : Shape
    {
        private double length;
        private double width;

        public Rectangle(double length, double width)
        {
            this.length = length;
            this.width = width;
        }

        public override double Area
        {
            get { return length * width; }
        }

        public override bool IsValid()
        {
            return length > 0 && width > 0;
        }
    }

    class Square : Rectangle
    {
        public Square(double sideLength) : base(sideLength, sideLength)
        {
        }
    }

    class Triangle : Shape
    {
        private double side1;
        private double side2;
        private double side3;

        public Triangle(double side1, double side2, double side3)
        {
            this.side1 = side1;
            this.side2 = side2;
            this.side3 = side3;
        }

        public override double Area
        {
            get
            {
                double s = (side1 + side2 + side3) / 2.0;
                return Math.Sqrt(s * (s - side1) * (s - side2) * (s - side3));
            }
        }

        public override bool IsValid()
        {
            return side1 + side2 > side3 && side2 + side3 > side1 && side3 + side1 > side2;
        }
    }
}

